import { _decorator, Component, Input, Node, Sprite } from 'cc';
import { SOUND_TYPE } from '../../../Data/GlobalData';
const { ccclass, property } = _decorator;

@ccclass('LineSingleMajiang')
export class LineSingleMajiang extends Component {

    //麻将
    @property(Sprite)
    private MajiangSprite: Sprite = null;

    //锁
    @property(Node)
    public LockNode: Node = null;

    //麻将名称
    public MajiangName: string = "";

    protected onLoad(): void {
        this.node.on(Input.EventType.TOUCH_START, this.UnLock, this)
    }

    /**
     * 初始化
     */
    public Init(_islock: boolean) {
        this.LockNode.active = _islock;
        this.MajiangSprite.node.active = false;
    }

    /**
     * 更新麻将样式
     */
    public UpdateMajiangSprite(_name: string) {
        this.MajiangName = _name;
        this.MajiangSprite.spriteFrame = app.resManager.SpriteFrames[_name];
    }

    /**
     * 
     */
    public UnLock() {
        if (!this.LockNode.active) return;
        app.audioManager.PlayEffect(SOUND_TYPE.Button);

        app.adManager.ShowVideo(0, (_isend: boolean) => {
            if (_isend) {
                this.LockNode.active = false;
                app.topManager.ShowPrompt("解锁成功");
            } else {
                app.topManager.ShowPrompt("解锁失败");
            }
        })
    }


}


